package com.admin.business.background.venusOaRaiseApproval;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 加薪审批表
 * @create: 2023-10-31 16:24:57
 **/
@Service("venusOaRaiseApprovalService")
@Slf4j
public class VenusOaRaiseApprovalService{

    @Resource
    VenusOaRaiseApprovalDao venusOaRaiseApprovalDao;

    /**
     * 添加加薪审批表,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - pid:上一次审批id
     *                   - org_id:申请人公司id
     *                   - post_id:申请人岗位id
     *                   - user_id:申请人
     *                   - approver_id:应审批人
     *                   - actual_approver_id:实审批人
     *                   - content:申请原因
     *                   - approver_state:审批状态( 0 待审批 1 审批成功 2 审批失败)
     *                   - approver_money:申请金额
     *                   - apply_money:审批金额
     *                   - note:备注
     *                   - approver_time:审批时间
     *                   - begin_time:创建时间
     *                   - state:状态 0 正常 1 删除
     * @return
     * @author Ht
     * @create: 2023-10-31 16:24:57
     */
    @OpenApi
    public Return addVenusOaRaiseApproval(CDO cdoRequest) {
        venusOaRaiseApprovalDao.addVenusOaRaiseApproval(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新加薪审批表数据
     *
     * @param cdoRequest - id:主键id
     *                   - pid:上一次审批id
     *                   - org_id:申请人公司id
     *                   - post_id:申请人岗位id
     *                   - user_id:申请人
     *                   - approver_id:应审批人
     *                   - actual_approver_id:实审批人
     *                   - content:申请原因
     *                   - approver_state:审批状态( 0 待审批 1 审批成功 2 审批失败)
     *                   - approver_money:申请金额
     *                   - apply_money:审批金额
     *                   - note:备注
     *                   - approver_time:审批时间
     *                   - begin_time:创建时间
     *                   - state:状态 0 正常 1 删除
     * @return
     * @author Ht
     * @create: 2023-10-31 16:24:57
     */
    @OpenApi
    public Return updateVenusOaRaiseApprovalById(CDO cdoRequest) {
        venusOaRaiseApprovalDao.updateVenusOaRaiseApprovalById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除加薪审批表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-10-31 16:24:57
     */
    @OpenApi
    public Return deleteVenusOaRaiseApprovalById(CDO cdoRequest){
        int count = venusOaRaiseApprovalDao.deleteVenusOaRaiseApprovalById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除加薪审批表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-31 16:24:57
     */
    @OpenApi
    public Return deleteVenusOaRaiseApproval(CDO cdoRequest) {
        int count = venusOaRaiseApprovalDao.deleteVenusOaRaiseApproval(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取加薪审批表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-10-31 16:24:57
     */
    @OpenApi
    public Return getVenusOaRaiseApprovalById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaRaiseApprovalDao.getVenusOaRaiseApprovalById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取加薪审批表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-31 16:24:57
     */
    @OpenApi
    public Return getVenusOaRaiseApprovalListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaRaiseApprovalDao.getVenusOaRaiseApprovalListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaRaiseApprovalDao.getVenusOaRaiseApprovalCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取加薪审批表数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author Ht
     * @create: 2023-10-31 16:24:57
     */
    @OpenApi
    public Return getVenusOaRaiseApprovalListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaRaiseApprovalDao.getVenusOaRaiseApprovalListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaRaiseApprovalDao.getVenusOaRaiseApprovalCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
